// pkg_shop/pages/shopEdit/shopEdit.js
import request from '../../../utils/http.js'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dianPuId: 0, //店铺id
    mingCheng:'',
    logoImg:'',
    teSe:'',
    diZhi:'',
    dianHua:'',
    swiperList:[],


    index:0,
    nameDate:0,
    jianjieData:0,
    dizhiData:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.setData({
        index:options.index,
        dianPuId:wx.getStorageSync(app.globalData.SHOPID)
      })
      var typeStr=''
      switch (options.index) {
        case '1':
          typeStr = '店铺名称';
          break;
        case '2':
          typeStr = '特色简介';
          break;
        case '3':
          typeStr = '地址';
          break;
        case '4':
          typeStr = '联系电话';
          break;
        default:
          typeStr = '其他';
      }

      wx.setNavigationBarTitle({
        title: typeStr 
      })


  },


  bindNameInput:function(e){
    var value = e.detail.value;
    var len = parseInt(value.length);
    this.setData({
      mingCheng:value,
      nameDate:len
    })
    
  },

  bindTeseInput:function(e){
    var value = e.detail.value;
    var len = parseInt(value.length);
    this.setData({
      teSe:value,
      jianjieData:len
    })
    
  },

  bindDizhiInput:function(e){
    var value = e.detail.value;
    var len = parseInt(value.length);
    this.setData({
      diZhi:value,
      dizhiData:len
    })
  },

  bindPhoneInput:function(e){
    var value = e.detail.value;
    this.setData({
      dianHua:value,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      this.getShoppingInfo();
  },

    //获取店铺信息
    getShoppingInfo: function () {

      var that = this

      let data = {
        dianPuId: that.data.dianPuId
      }
      request.get('dianPu/basicInfo', data, res => {

        that.setData({
          mingCheng: res.data.mingCheng,
          nameDate:res.data.mingCheng.length,
          logoImg: res.data.logo,
          teSe: res.data.teSe,
          jianjieData:res.data.teSe.length,
          diZhi: res.data.diZhi,
          dizhiData:res.data.diZhi.length,
          dianHua: res.data.dianHua,
        })
  
        // wx.setStorageSync(app.globalData.ShopName, res.data.mingCheng);
        // wx.setStorageSync(app.globalData.ShopLogo, res.data.logo)
  
  
  
  
      }, err => {
  
      })
  
    },
  
    //修改信息
    updataShopInfo:function(){
      var that = this

      var ziDuan=''
      switch (that.data.index) {
        case '1':
          ziDuan = that.data.mingCheng;
          break;
        case '2':
          ziDuan = that.data.teSe;
          break;
        case '3':
          ziDuan = that.data.diZhi;
          break;
        case '4':
          ziDuan = that.data.dianHua;
          break;
        default:
          ziDuan = '';
      }
      //console.log("that.data.index"+that.data.index)
      //console.log("联系电话："+ziDuan)
      let data = {
        dianPuId: that.data.dianPuId,
        leiXing:that.data.index,
        ziDuan:ziDuan
      }
      request.get('dianPu/setDianPuMingZi', data, res => {
  
      // console.log("respon:" + JSON.stringify(res.data))
        if(res.data.status==1){

          if(that.data.index==1){
            wx.setStorageSync(app.globalData.ShopName, ziDuan);
          }
          app.globalData.shopIsChange='true'
          wx.navigateBack({
            delta: 1
          })
        }else{
          wx.showToast({
            title: '修改失败', // 提示的内容
            icon: "none", // 图标，默认success
            duration: 1000, // 提示的延迟时间，默认1500
            mask: false, // 是否显示透明蒙层，防止触摸穿透
          })
        }
      }, err => {
        wx.showToast({
          title: '修改失败，请联系技术人员', // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1000, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿透
        })
      })
    },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})